<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>window</title>
</head>
<body>
<div onclick="stop()">停止</div>
<script type="text/javascript">

    let interval= function(){
        console.log(new Date()+"执行方法");
    }
    let x= setInterval(interval,1000);//与setTimeout()不同，1s后执行前面的函数或表达式

    function stop(){
        clearInterval(x);
    }
</script>
</body>
</html>